package lab02.test21;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //统计一个字符串中给定字符出现的频率。

        Scanner sc = new Scanner(System.in);
        int count = 0;

        System.out.println("请输入一个字符串:");
        String result = sc.next();
        System.out.println("请输入需要查询的字符:");
        String find = sc.next();


        for (int i = 0; i < result.length(); i++) {
            String c[] = result.split("");
            if (find.equals(c[i])) {
                count++;
            }
        }
        System.out.println(find + "的频率为：" + String.format("%.2f", (float) count / result.length()));
    }
}
